package com.woniuxy.mapper;

import com.woniuxy.entity.Blog;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BlogMapper {
    List<Blog> findBlogByTypeId(Integer id);

    /*
    * 博客的收藏数+1
    * */
    @Update("update blog set count=count+1 where id=#{itemId}")
    void plusOne(Integer itemId);

    /*
    * 博客的收藏数-1
    * */
    @Update("update blog set count=count-1 where id= #{itemId}")
    void subtractOne(Integer itemId);

    /*
    * 博客的评论数+1
    * */
    @Update("update blog set comment_count=comment_count+1 where id= #{itemId}")
    void plusOneCommentCount(Integer itemId);

    /*
    * 博客的评论数-1
    * */
    @Update("update blog set comment_count=comment_count-1 where id= #{itemId}")
    void subtractOneCommentCount(Integer itemId);


    @Select("select count(*) from blog where user_id= #{userId}")
    Integer publishCount(Integer userId);

    @Select("select count from blog where id= #{itemId}")
    Integer getBlogCount(Integer itemId);

    List<Blog> search(String blogName);

//    @Select("select * from blog where user_id= #{userId}")
    List<Blog> findUserBlog(Integer userId);

    @Select("select * from blog where id in (select item_id from conllection where user_id= #{userId})")
    List<Blog> findUserCollectBlog(Integer userId);

    int add(Blog blog);

    int addVideo(Blog blog);
}
